package Test;

import static org.junit.Assert.*;

import java.io.File;

import org.junit.Test;

import Model.Paper;
import Model.User;

public class TestPaper 
{
  private static final String TITLE = "The Joys of Paper Prototyping";
   
	public static final User TEST_AUTHOR = new User("Eric Cartman", "testAuthor", "testAuthor@yahoo.com");
	
	public static final User TEST_SUB_CHAIR = new User("Manny Pacquiao", "testSubChair", "testSubChair@yahoo.com");
	
	public File testFile = new File("test.txt");
	
	/**
	 * Tests the first constructor to make sure all the values are as expected.
	 */
	@Test
	public void testPaperConstructorArg1() 
	{
	  String expectedUserName = "testAuthor";
	  String expectedRealName = "Eric Cartman";
	  String expectedEmail = "testAuthor@yahoo.com";

	  
	  Paper testPaper = new Paper("The Joys of Paper Prototyping", TEST_AUTHOR, new File("test.txt"));
	  
	  assertEquals("The Author of the Paper", expectedUserName, testPaper.getAuthor().userName());
	  assertEquals("The Email of the User", expectedEmail, testPaper.getAuthor().email());
	  assertEquals("The Actual name of the author", expectedRealName, testPaper.getAuthor().realName());
	  
	  assertNotNull("There should be a manuscript", testPaper.getManuscript());
	  assertNull("There should be no SPC assigned to this paper yet", testPaper.getSubprogramChair());
	  
	}

	/**
	 * Tests the second constructor to make suer all the values stored are as expected.
	 */
	@Test
	public void testPaperConstructorArg2()
	{
	  Paper testPaper = new Paper(TITLE, TEST_AUTHOR, TEST_SUB_CHAIR, testFile);
	  
	  String expectedTitle = "The Joys of Paper Prototyping";
    String expectedUserName = "testAuthor";
    String expectedRealName = "Eric Cartman";
    String expectedEmail = "testAuthor@yahoo.com";
    
    assertEquals("The title of the paper", expectedTitle, testPaper.getTitle());
    assertEquals("The Author of the Paper", expectedUserName, testPaper.getAuthor().userName());
    assertEquals("The Email of the User", expectedEmail, testPaper.getAuthor().email());
    assertEquals("The Actual name of the author", expectedRealName, testPaper.getAuthor().realName());
    
    String expectedSubprogramUserName = "testSubChair";
    String expectedSubprogramRealName = "Manny Pacquiao";
    String expectedSubprogramEmail = "testSubChair@yahoo.com";
    
    assertEquals("The SPC of the Paper", expectedSubprogramUserName, testPaper.getSubprogramChair().userName());
    assertEquals("The Email of the SPC", expectedSubprogramEmail, testPaper.getSubprogramChair().email());
    assertEquals("The Actual name of the SPC", expectedSubprogramRealName, testPaper.getSubprogramChair().realName());
    
    assertNotNull("The file object shouldn't be empty", testPaper.getManuscript());
	}
	
	/**
	 * Should create multiple Paper objects and tests that the equals method is working properly
	 */
	@Test
	public void testEquals() 
	{
	  final User aAuthor = new User("Eric Cartman", "testAuthor", "testAuthor@yahoo.com");
	  
	  final User aSubChair = new User("Manny Pacquiao", "testSubChair", "testSubChair@yahoo.com");
	  
    Paper testPaper = new Paper(TITLE, TEST_AUTHOR, TEST_SUB_CHAIR, testFile);
    Paper equivalentPaper = new Paper("The Joys of Paper Prototyping", aAuthor, aSubChair, testFile);
    Paper differentPaper = new Paper("The Joys of Paper Prototyping", TEST_SUB_CHAIR, new File("test.txt"));
    
    
    if (!testPaper.equals(equivalentPaper))
      fail("The equals method failed for similar objects");
    
    assertNotSame("These instance's of Paper should be different", testPaper, differentPaper);
    
    if (testPaper.equals(differentPaper))
      fail("These instance's of paper should be different");
	}
}
